<template>
  <div>
    <el-form-item :prop="item.name || ''" :label="item.label" v-bind="item.formItemProps || {}" ref="el-form-item">
      <el-switch v-model="mvalue" v-bind="opt"></el-switch>
    </el-form-item>
  </div>
</template>

<script>
  import { objectAssign } from "../../utils/common";
  import Required from "../validMixins/Required";

  export default {
    name: "PopoSwitch",
    props: {
      value: { type: [Boolean, String, Number] },
      item: { type: Object },
      formData: { type: Object },
    },
    mixins: [ Required],
    data() {
      return {
        mvalue: this.value,
        opt: {},
      };
    },
    watch: {
      mvalue(val) {
        this.$emit("input", val);
      },
    },
    created() {
      // console.log( "input", this);
      var opt = objectAssign(
        {
          activeValue: this.item.activeValue !== undefined ? this.item.activeValue : true,
          inactiveValue: this.item.inactiveValue !== undefined ? this.item.inactiveValue : false,
          activeText: this.item.activeText !== undefined ? this.item.activeText : "",
          inactiveText: this.item.inactiveText !== undefined ? this.item.inactiveText : false,
        },
        this.item.props
      );

      if (this.mvalue === undefined) {
        this.mvalue = opt.inactiveValue;
      }

      this.opt = opt;
    },
    methods: {},
  };
</script>

